package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.utils.SecurityUtils;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.vo.BizMessageConversationFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizMessageConversationQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizMessageConversationVO;
import cn.sfrog.project.biz.admin.service.IBizMessageConversationService;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "聊天会话接口")
@RestController
@RequestMapping("/biz/messageConversation")
public class BizMessageConversationController extends BaseController {
    @Resource
    private IBizMessageConversationService bizMessageConversationService;

    /**
     * 查询聊天会话列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:messageConversation:list')")
    @GetMapping("/list")
    public AjaxResult list(BizMessageConversationQueryVO queryVO) {
        queryVO.setReceiveUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        List<BizMessageConversationVO> list = bizMessageConversationService.selectBizMessageConversationList(queryVO);
        return AjaxResult.success(list);
    }

    /**
     * 导出聊天会话列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:messageConversation:export')")
    @Log(title = "聊天会话", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizMessageConversationQueryVO query) {
        List<BizMessageConversationVO> list = bizMessageConversationService.selectBizMessageConversationList(query);
        ExcelUtil<BizMessageConversationVO> util = new ExcelUtil<BizMessageConversationVO>(BizMessageConversationVO.class);
        util.exportExcel(response, list, "聊天会话数据");
    }

    /**
     * 获取聊天会话详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:messageConversation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizMessageConversationService.selectBizMessageConversationById(id));
    }

    /**
     * 新增聊天会话
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:messageConversation:add')")
    @Log(title = "聊天会话", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizMessageConversationFormVO form) {
        return toAjax(bizMessageConversationService.insertBizMessageConversation(form));
    }

    /**
     * 修改聊天会话
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:messageConversation:edit')")
    @Log(title = "聊天会话", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizMessageConversationFormVO form) {
        return toAjax(bizMessageConversationService.updateBizMessageConversation(form));
    }

    /**
     * 删除聊天会话
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:messageConversation:remove')")
    @Log(title = "聊天会话", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizMessageConversationService.deleteBizMessageConversationByIds(ids));
    }

    /**
     * 更改状态聊天会话
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasPermi('biz:messageConversation:changeStatus')")
    @Log(title = "聊天会话", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizMessageConversationService.changeStatus(vo));
    }


}
